﻿using System;

public interface IShape
{
    double CalculateArea();
    bool IsValid();
}

public abstract class Shape : IShape
{
    public abstract double CalculateArea();
    public abstract bool IsValid();
}

public class Rectangle : Shape
{
    public double Length { get; set; }
    public double Width { get; set; }

    public Rectangle(double length, double width)
    {
        Length = length;
        Width = width;
    }

    public override double CalculateArea()
    {
        return IsValid() ? Length * Width : 0;
    }

    public override bool IsValid()
    {
        return Length > 0 && Width > 0;
    }
}

public class Square : Rectangle
{
    public Square(double side) : base(side, side) { }
}

public class Triangle : Shape
{
    public double SideA { get; set; }
    public double SideB { get; set; }
    public double SideC { get; set; }

    public Triangle(double sideA, double sideB, double sideC)
    {
        SideA = sideA;
        SideB = sideB;
        SideC = sideC;
    }

    public override double CalculateArea()
    {
        if (!IsValid())
            return 0;

        double s = (SideA + SideB + SideC) / 2;
        return Math.Sqrt(s * (s - SideA) * (s - SideB) * (s - SideC));
    }

    public override bool IsValid()
    {
        return SideA + SideB > SideC && SideA + SideC > SideB && SideB + SideC > SideA;
    }
}

class Program
{
    static void Main(string[] args)
    {
        Rectangle rectangle = new Rectangle(5, 10);
        Console.WriteLine($"长方形的面积: {rectangle.CalculateArea()}");

        Square square = new Square(4);
        Console.WriteLine($"正方形的面积: {square.CalculateArea()}");

        Triangle triangle = new Triangle(3, 4, 5);
        Console.WriteLine($"三角形的面积: {triangle.CalculateArea()}");
        Console.Read();
    }
}
